package com.example.lx6_3

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.base.entity.AddVisParam
import com.example.base.mvvm.BaseActivity
import com.example.lx6_3.adapter.VisitAdapter
import com.example.lx6_3.databinding.ActivityMainBinding
import com.example.lx6_3.visit.VisitViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding,VisitViewModel>() {

    val visitAdapter by lazy { VisitAdapter() }

    override fun initView() {
        binding.rv.apply {
            adapter = visitAdapter
            layoutManager = LinearLayoutManager(this@MainActivity)
        }
        vm.getVisit()

        binding.ivAdd.setOnClickListener {
            ARouter.getInstance().build("/app/AddVisActivity").navigation()
        }
    }

    override fun initData() {
        vm.visitData.observe(this){
            visitAdapter.data.clear()
            visitAdapter.data.addAll(it)
            visitAdapter.notifyDataSetChanged()
        }
    }

    override fun onResume() {
        super.onResume()
        vm.getVisit()
    }
}